package com.ft.adbix.core.ad;

import android.content.Context;

import com.ft.adbix.core.ad.base.BaseAd;
import com.ft.adbix.core.ad.manager.RewardAdManager;
import com.ft.adbix.core.listener.RewardListener;
import com.ft.adbix.core.response.Ad;
import com.ft.adbix.core.view.activity.RewardVideoActivity;

public class RewardAd extends BaseAd {

    public RewardAd(Context context, Ad adData) {
        super(context, adData);
        RewardAdManager.getInstance().saveRewardAdData(adData);
    }

    public void setRewardListener(RewardListener rewardListener) {
        RewardAdManager.getInstance().saveRewardAdListener(adData.getReqId(), rewardListener);
    }

    public void showReward(Context context) {
        if (adData == null || hasShown) {
            return;
        }
        hasShown = true;
        RewardVideoActivity.start(context, adData.getReqId());
    }

    @Override
    public void release() {
        if (adData != null) {
            RewardAdManager.getInstance().removeReward(adData.getReqId());
        }
    }
}
